<template>
	<view >
		<view class="uni-title">仪器耗材选择列表</view>
		<view class="search-box">
			<uni-search-bar :radius="25" @input="search" @cancel="cancel" cancelButton="none" placeholder="输入仪器耗材名称"></uni-search-bar>
		</view>
		<scroll-view scroll-y="true" class="scroll-wrap">
			<view class="list-box">
				<evan-radio-group v-model="activeId">
					<evan-radio ﻿v-for="opt in list" :key="opt.cCusCode" :label="opt.cCusCode">{{opt.cCusName}}</evan-radio>
				</evan-radio-group>
				<view class="btn-box">
					<button type="default" @click="save">确定</button>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {Url,bpmUrl} from "@/common/config.js"
	import {ajax,getUserInfo} from '@/common/common.js'
	export default {
		data() {
			return {
				list: [],
				activeCustomer: {},
				activeId: '',
				user: {},
				bpmSearch: {
					paramasMap: {},
					headersMap: {
						sysid: "bpm",
						syspwd: "pass",
						userid: ''
					},
					url: ''
				},
			};
		},
		onShow() {
			console.log('show')
			this.initCustomerList()
		},
		methods:{
			initCustomerList(){
				let user = uni.getStorageSync("user_info")
				console.log('用户',user)
				let searchField = this.bpmSearch
				searchField.headersMap.userid = user.bpmUid
				searchField.url = bpmUrl + '/rest/appform/getInstrumentConsumablesData'
				console.log(searchField)
				ajax({
					url: '/bpm/get',
					method: 'POST',
					data: searchField,
					success: res => {
						console.log(res)
						res.data.data = [{icon:"111",WF_OrUnid: "123",cInvCode:"10000", cCusName:"测试测试", cInvStd: "测试规格",num:"1"}]
						this.list = res.data.data
					}
				})
			},
			search(e){
				// this.bpmSearch.paramasMap.cCusName = e.value
				this.bpmSearch.paramasMap.DocUnid= "96fd347f061ae04d9e0b67509d8c144af07b"
				this.initCustomerList()
			},
			cancel(e){
				this.bpmSearch.paramasMap = {}
				this.initCustomerList()
			},
			save(){
				let arr = this.list.filter(item => item.cCusCode == this.activeId )
				if(arr.length > 0){
					this.$emit('confirm',arr[0])
				}else{
					uni.showToast({
						title:'请选择客户',
						icon:'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
.uni-title{
	font-size: 32rpx;
	padding: 30rpx 0;
	text-align: center;
}
.evan-radio{
	padding: 10px;
	border-bottom: 1px solid #eee;
}
.btn-box{
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
}
</style>
